﻿@model IEnumerable<MVCDriver.Models.DriverInfo>

<p>
    @Html.ActionLink("添加", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Age)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Mobile)
            @*@Html.DisplayName("电话")*@
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TruckInfo.Number)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Age)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Mobile)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TruckInfo.Number)
            </td>
            <td>
                <input id="Button1" type="button" value="刘远真衰" />
                @Html.ActionLink("修改", "Edit", new { id = item.DriverID }) |
                @Html.ActionLink("详情", "Details", new { id = item.DriverID }) |
                @*@Html.ActionLink("删除", "Delete", new { id=item.DriverID })*@

                <a href="javascript:;" onclick="deleteStudent(@item.DriverID)" >删除</a>
            </td>
        </tr>
    }

</table>
@section Scripts
    {
    <script>
        //删除学员
        function deleteStudent(id) {
            //如果确认删除则进行删除操作
            if (confirm("确定要删除吗？")) {
                //使用Ajax请求删除该记录
                $.post("@Url.Action("Delete", "Driver")", { Id: id }, function (data) {
                    //如果执行成功则刷新页面重新进行数据绑定
                    if (data.IsSuccess) {
                        location.reload();
                    }
                    else {
                        alert(data.ErrorMessage);
                    }

                }, "json");
            }
        }

    </script>
}